package com.wavehi.dao.impl;

import com.wavehi.dao.BaseDao;
import com.wavehi.pojo.Person;

import java.util.List;

/**
 * @Author WaveHi
 * @Date 3/9/2021 下午 8:24
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
public class PersonDAOImpl extends BaseDao implements IPersonDAO {
    @Override
    public void add(Person person) {
        String sql = "insert into t_person(p_name, p_age) values(?, ?)";
        update(sql,person.getName(),person.getAge());
    }

    @Override
    public void delete(Long id) {
        String sql = "delete from t_person where p_id=?";
        update(sql,id);
    }

    @Override
    public void update(Person person) {
        String sql = "update t_person set p_name=?, p_age=? where p_id=?";
        update(sql,person.getName(), person.getAge(), person.getId());
    }

    @Override
    public Person select(String name) {
        String sql = "select p_id id, p_name name,p_age age from t_person where p_name=?";
        return selectForOne(Person.class,sql,name);
    }

    @Override
    public List<Person> List() {
        String sql = "select p_id id, p_name name, p_age age from t_person";
        return selectForList(Person.class, sql);
    }
}
